package com.jwater.core.net;

import jwater.io.netty.buffer.ByteBuf;
import jwater.io.netty.channel.ChannelHandlerContext;
import jwater.io.netty.handler.codec.MessageToByteEncoder;
/**
 * @description:
 * @author: jnner
 * @createDate: 2021/2/5
 * @version: 1.0
 */
public class NettyEncoder extends MessageToByteEncoder<NodePacket> {

	@Override
	protected void encode(ChannelHandlerContext context, NodePacket packet, ByteBuf buf) throws Exception {
		buf.writeShort(packet.getVersion());
		buf.writeInt(packet.getDataType());
		buf.writeInt(packet.getNumber());
		buf.writeInt(packet.getLength());
		if (packet.getLength() > 0) {
			buf.writeBytes(packet.getData());
		}
	}

}
